package model.entity;

import com.sun.xml.internal.bind.v2.model.core.ID;
import model.entity.Item;
import model.enums.OrderStatus;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * 订单实体类
 *
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/25 9:14
 */
public class Order {
    /**
     * 订单id
     */
    private String orderId;
    /**
     * 商品列表
     */
    private List<Item> items;
    /**
     * 订单状态
     */
    private OrderStatus status;
    /**
     * 总价
     */
    private Double totalPrice;
    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 订单备注
     */
    private String remark;

    public Order() {
    }

    public Order(String orderId, OrderStatus status, LocalDateTime createTime) {
        this.orderId = orderId;
        this.status = status;
        this.createTime = createTime;
    }

    public Order(String orderId, List<Item> items, OrderStatus status, Double totalPrice, LocalDateTime createTime) {
        this.orderId = orderId;
        this.items = items;
        this.status = status;
        this.totalPrice = totalPrice;
        this.createTime = createTime;
    }

    public Order(String orderId, List<Item> items, OrderStatus status, Double totalPrice, LocalDateTime createTime, String remark) {
        this.orderId = orderId;
        this.items = items;
        this.status = status;
        this.totalPrice = totalPrice;
        this.createTime = createTime;
        this.remark = remark;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public Double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public void appendRemark(String remark) {
        if (Objects.isNull(this.remark)) {
            this.remark = remark;
        } else {
            this.remark += "\n" + remark;
        }
    }

    @Override
    public String toString() {
        return "Order{" +
                "orderId='" + orderId + '\'' +
                ", items=" + items +
                ", status=" + status +
                ", totalPrice=" + totalPrice +
                ", createTime=" + createTime +
                ", remark='" + remark + '\'' +
                '}';
    }
}
